To use the covidData package, you must first do some set-up to install the package and download the data from various sources. It is not as straight-forward as installing a normal R package. The latest instructions on how to install the package can be found on the package’s GitHub page.
The following code retrieves and plots case and death data from JHU CSSE and hospitalization data from HealthData.gov. For more details about how these data are computed and what sources they come from, please see the COVID-19 Forecast Hub Technical README file.
library(dplyr)
library(ggplot2)
library(covidData)
# Load incident cases, hospitalizations, and deaths data at state level
combined_data <- dplyr::bind_rows(
load_jhu_data(
issue_date = "2020-12-02",
temporal_resolution = "daily",
measure = "cases"
) %>%
dplyr::mutate(measure = "cases"),
load_jhu_data(
issue_date = "2020-12-02",
temporal_resolution = "daily",
measure = "deaths"
) %>%
dplyr::mutate(measure = "deaths"),
load_healthdata_data(
issue_date = "2020-12-02",
temporal_resolution = "daily",
measure = "hospitalizations"
) %>%
dplyr::mutate(measure = "hospitalizations")
)
# Add more human readable location names
combined_data <- combined_data %>%
dplyr::left_join(
covidData::fips_codes,
by = "location"
)
# Plot the data
ggplot(
data = combined_data,
#data = filter(combined_data, abbreviation %in% c("MA", "SD", "TX")),
mapping = aes(x = date, y = inc, color = measure)) +
geom_smooth(se=FALSE, span=.25) +
geom_point(alpha=.2) +
facet_wrap( ~ abbreviation, ncol = 3, scales = "free_y") +
scale_y_log10() +
#scale_x_date(limits=c(as.Date("2020-07-01"), Sys.Date())) +
theme_bw()